﻿Public Class LvlCompare

    Public ComparePoints As New List(Of LvlPoint)
    Private mInstrCenterLevel As Double = 9999



    Sub Add(ByVal Name As String, ByVal Level As Single)
        Dim vP As New LvlPoint
        vP.Name = Name
        vP.Level = Level
        ComparePoints.Add(vP)
    End Sub

    Sub Add(ByVal vP As LvlPoint)
        Add(vP.Name, vP.Level)
    End Sub

    '比较高差
    Function CompareHeight(ByVal svName As String, ByVal cmpName As String) As Single
        Dim svLvl As Single, svFound As Boolean = False
        Dim cmpLvl As Single, cmpFound As Boolean = False
        For Each cp1 As LvlPoint In ComparePoints
            If Not svFound Then
                If cp1.Name = svName Then
                    svLvl = cp1.Level
                    svFound = True
                End If
            End If
            If Not cmpFound Then
                If cp1.Name = cmpName Then
                    cmpLvl = cp1.Level
                    cmpFound = True
                End If
            End If

            If svFound And cmpFound Then
                Return svLvl - cmpLvl
            End If
        Next

        Return 9999
    End Function


    '设置仪器中心高
    Sub SetInstrCenterLevel(ByVal Name As String, ByVal Read As String)
        If Name.Trim.Length > 0 And Read.Trim.Length > 0 Then
            Dim vP As New LvlPoint
            If SearchByName(Name, vP) Then
                mInstrCenterLevel = vP.Level + CDbl(Read) * MyShared.ProjectOpt.MidReadUnit  'lvlRegistry.OptionDef.Read_Unit
            End If
        End If
    End Sub

    Sub SetInstrCenterLevel()
        mInstrCenterLevel = 9999
    End Sub

    '大致读数
    Function GetRoundRead(ByVal Name As String, ByRef sRead As String) As Boolean
        If mInstrCenterLevel < 9000 Then
            Dim vP As New LvlPoint
            If SearchByName(Name, vP) Then
                'sRead = Format((mInstrCenterLevel - vP.Level) / lvlRegistry.OptionDef.Read_Unit, "000000")
                sRead = Format((mInstrCenterLevel - vP.Level) / MyShared.ProjectOpt.MidReadUnit, "000000")
                Return True
            End If
        End If
        Return False
    End Function
    Private Function SearchByName(ByVal Name As String, ByRef FoundPnt As LvlPoint) As Boolean
        For Each vP As LvlPoint In ComparePoints
            If vP.Name = Name Then
                FoundPnt = vP
                Return True
            End If
        Next
        Return False
    End Function

End Class


